package cn.qiyu5522.controller;


import cn.qiyu5522.domain.DTO.UserInfoDTO;
import cn.qiyu5522.domain.entity.ResponseResult;
import cn.qiyu5522.group.Add;
import cn.qiyu5522.group.Update;
import cn.qiyu5522.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2024-04-11
 */
@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "查询用户信息",notes = "查询登录用户信息")
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){
        return userService.userInfo();
    }

    @ApiOperation(value = "更新用户信息",notes = "接收JSON，修改用户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userInfoDTO",value = "用户DTO类"),
    })
    @PutMapping("/userInfo")
    public ResponseResult addUserInfo(@Validated({Update.class})  @RequestBody UserInfoDTO userInfoDTO){
        return userService.updateUserInfo(userInfoDTO);
    }

    @ApiOperation(value = "用户注册",notes = "接收JSON，用户注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userInfoDTO",value = "用户DTO类"),
    })
    @PostMapping("/register")
    public ResponseResult register(@Validated({Add.class}) @RequestBody UserInfoDTO userInfoDTO){
        return userService.register(userInfoDTO);
    }

}
